// 开展培训
function ProjectStartTrain() {
    var _this = this;
    var page;
    _this.page_size = 10;

    // init
    _this.init = function(_page) {
        page = _page;
        _this.initTable();
        _this.initEvent();
        // 表头学时汇总
        _this.sumStudyTime();
    };

    _this.initTable = function() {
        var list_url = appPath + "/admin/projectCenterTrain/showCourseList";
        page.init("select_course_form", list_url, "select_course_list", "select_course_page", 1, _this.page_size);
        page.goPage(1);
        page.list = function(dataList){
            _this.obj = dataList;
            if(dataList == null){
                return;
            }
            var len = dataList.length;
            var inner = "", item;
            var status = "";
            // 组装数据
            for(var i=0; i< len; i++) {
                item = dataList[i];
                // 组装数据
                inner += "<tr>";
                inner += '<td width="100">'+(parseInt(i)+1)+'</td>';
                // inner += '<td  width="100">'+ item['course_no'] + '</td>';
                inner += '<td width="160"><span class="text-orange tooltip" data-length="15">'+ item['course_name'] + '</span></td>';
                inner += '<td width="100">'+ TimeUtil.getHouAndMinAndSec(item['requirement']*60) + '</td>';   //requirement应修学时;class_hour课时
                inner += '<td width="100">'+ TimeUtil.getHouAndMinAndSec(item['study_time'])+ '</td>';   //已修学时
                status = item['requirement']*60 > item['study_time'] ? "未完成" : "已完成";
                inner += '<td width="100">'+ status + '</td>';   //状态

                inner += '<td width="100">';
                inner += '<a href="javascript:projectStartTrain.courseView(\''+ item['course_id'] +'\');" class="a a-view">播放</a> ';
                inner += "</td>";
                inner += "</tr>";
            }
            return inner;
        }

    };



    _this.initEvent = function () {
        //搜索
        $("#courseName_search").click(function () {
            _this.initTable();
        });

        //全部
        $("#course_all").click(function () {
            $("#courseName").val("");
            _this.initTable();
        });


    };

    var outerWindow_study_status = false;

    //课程播放
    _this.courseView=function (courseId) {
        // common.goto_student_study(null,courseId,null,null);

        //进入管理员播放学习
        var study_url = appPath + "/admin/projectCenterTrain/study?projectId="+$("#projectId").val()+"&courseId=" + courseId;
        if(outerWindow_study_status) {
            var winOpn = window.open("", "student_study");
            if(winOpn.location.href.indexOf(study_url) == -1){
                window.open(study_url, "student_study","",true);
            }else{
                window.open("", "student_study","",true);
            }
        } else {
            window.open(study_url, "student_study");
            outerWindow_study_status = true;
        }
    };



    // 学时汇总
    _this.sumStudyTime = function () {
        $.ajax({
            url: appPath + '/admin/projectCenterTrain/sumStudyTime',
            async: false,
            type: 'post',
            data: {
                'projectId': $("#projectId").val()     // 项目id
            },
            success: function (data) {
                var code = data['code'];
                if (code == 10000) {
                    var result = data['result'];
                    $("#requirementStudyTime").text(TimeUtil.getHouAndMinAndSec(result['requirementStudyTime']*60));
                    $("#studyTime").text(TimeUtil.getHouAndMinAndSec(result['studyTime']));

                } else {
                    layer.alert('操作失敗', {icon: 2, skin: 'layer-ext-moon'});
                }
            }
        });
    }

}

var projectStartTrain = new ProjectStartTrain();